<?php
// 全局中间件定义文件
namespace app\middleware;

class AuthMiddleware
{
    public function handle($request, \Closure $next)
    {

        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: Content-Type, Authorization');

        $token = $request->header('auth');
        if (!$token) {
            return error("Token不能为空", 401);
        }

        return $next($request);
    }
}
